package mytest.ssw.www.myandroidproject.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import mytest.ssw.www.myandroidproject.R;
import mytest.ssw.www.myandroidproject.activity.PictureWordActivity;


/**
 * Created by 73409 on 2015/10/28.
 */

public class Mybaseadapter extends BaseAdapter{
    private Context context;
    LayoutInflater inflater;
    String[] names;
    int[] pictures;
    public Mybaseadapter(Context context,String[] names,int[] pictures) {
        this.context=context;
         inflater =LayoutInflater.from(context);
        this.names=names;
        this.pictures=pictures;
    }

    @Override

    public int getCount() {
        return 9;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView==null) {
           convertView  = inflater.inflate(R.layout.gridvoew_item, parent, false);
            viewHolder =new ViewHolder();
            viewHolder.textView=(TextView)convertView.findViewById(R.id.textname);
            viewHolder.imageView=(ImageView)convertView.findViewById(R.id.imagename);
            convertView.setTag(viewHolder);
       }
       else {
            viewHolder=(ViewHolder)convertView.getTag();
        }
        viewHolder.imageView.setImageResource(pictures[position]);
        viewHolder.textView.setText(names[position]);
        return convertView;
    }
    static  class ViewHolder
    {
        TextView textView;
        ImageView imageView;
    }
}
